using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;

namespace OurWedding1.Models
{ 
    public class MustHaveSongRepository : IMustHaveSongRepository
    {
        readonly WeddingEntities _context = new WeddingEntities();

        public IQueryable<MustHaveSong> All
        {
            get { return _context.MustHaveSongs; }
        }

        public IQueryable<MustHaveSong> AllIncluding(params Expression<Func<MustHaveSong, object>>[] includeProperties)
        {
            IQueryable<MustHaveSong> query = _context.MustHaveSongs;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public MustHaveSong Find(int id)
        {
            return _context.MustHaveSongs.Find(id);
        }

        public void InsertOrUpdate(MustHaveSong musthavesong)
        {
            if (musthavesong.MustHaveSongId == default(int)) {
                // New entity
                _context.MustHaveSongs.Add(musthavesong);
            } else {
                // Existing entity
                _context.Entry(musthavesong).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var musthavesong = _context.MustHaveSongs.Find(id);
            _context.MustHaveSongs.Remove(musthavesong);
        }

        public void Save()
        {
            _context.SaveChanges();
        }

        public void Dispose() 
        {
            _context.Dispose();
        }
    }

    public interface IMustHaveSongRepository : IDisposable
    {
        IQueryable<MustHaveSong> All { get; }
        IQueryable<MustHaveSong> AllIncluding(params Expression<Func<MustHaveSong, object>>[] includeProperties);
        MustHaveSong Find(int id);
        void InsertOrUpdate(MustHaveSong musthavesong);
        void Delete(int id);
        void Save();
    }
}